#!/sbin/openrc-run

# fallback for /etc/conf.d/adguardhome
: ${command_user:=adguardhome:adguardhome}
: ${directory:="/var/lib/adguardhome"}
: ${cfgfile:="$directory/AdGuardHome.yaml"}
: ${extra_args=""}

name=adguardhome
description="AdGuardHome daemon"
command="/usr/bin/adguardhome"
command_args="--no-check-update --work-dir $directory --config $cfgfile $extra_args"
command_background=true
pidfile="/run/adguardhome.pid"
capabilities="^cap_net_bind_service,^cap_net_raw"

depend() {
	need net
	provide dns
	after firewall
}

start_pre() {
	checkpath -d -o "$command_user" "$directory"

	if [ -n "$logdir" ]; then
		checkpath -d -o "$command_user" "$logdir"
	fi

	if [ -n "$output_log" ]; then
		checkpath -f -o "$command_user" "$output_log"
	fi

	if [ -n "$error_log" ]; then
		checkpath -f -o "$command_user" "$error_log"
	fi
}
